﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataShow.ascx
{
    public partial class _5site1 : System.Web.UI.UserControl
    {
        public string StationCode { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region 填充面板数据
        /// <summary>
        /// 填充面板数据
        /// </summary>
        public void FillPanelData(DateTime date, string sendpoints, string element)
        {
            
            List<codeModel.ForeSpanType> spans = new List<codeModel.ForeSpanType>()
            {
                codeModel.ForeSpanType.FD00_24,
                codeModel.ForeSpanType.FD24_48,
                codeModel.ForeSpanType.FD48_72,
                codeModel.ForeSpanType.FD72_96,
                codeModel.ForeSpanType.FD96_120,
                codeModel.ForeSpanType.FD120_144,
                codeModel.ForeSpanType.FD144_168
            };//时效
            string[] tables = new string[] { "SjwrfFore", "LYGWrfFore", "T639Fore", "Jma_ThinFore", "EC_ThinFore", "EnsembleFore", "GrapesFore", "GfsFore", "SHwrfFore", "TQZXFore", "JSjxhFore", "STFore", "Wrf3kmFore", "Wrf15kmFore", "Zyt_CityFore" }; //表名
            codeDAL.SqlHelper sqlhelper = new codeDAL.SqlHelper();
            int foreSpanPointer = 0, tablePointer = 0;

            for (int i = 0; i < this.panel.Controls.Count; i++)
            {
                Control control = this.panel.Controls[i];
                if (control is Label)
                {
                    string sql = string.Format("select * from {0} where date='{1}' and sendpoint='{2}' and [type]='{3}' and span='{4}'", tables[tablePointer], date.ToString("yyyyMMdd"), sendpoints, element, spans[foreSpanPointer]);
                    DataTable dt = sqlhelper.ExecuteQuery(sql, CommandType.Text);
                    if (dt.Rows.Count > 0)
                    {
                        string StationValues = dt.Rows[0]["value"].ToString();
                        string[] items = StationValues.Split('|');
                        for (int j = 0; j < items.Length; j++)
                        {
                            if (items[j].Contains(StationCode))
                            {
                                string value = items[j].Split(';')[1];
                                (control as Label).Text = value;
                                
                            }
                        }
                    }
                    foreSpanPointer++;
                    if (foreSpanPointer > 6)
                    {
                        foreSpanPointer = foreSpanPointer % 7;
                        tablePointer++;
                        if (tablePointer > (tables.Length - 1))
                        {
                            return;
                        }
                    }
                }
            }

        } 
        #endregion
    }
}